/* eslint valid-jsdoc: "off" */

'use strict';
/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1588586742343_2203';
  config.security = {
    csrf: {
      enable: false,//关闭egg自带的 post提交csrf安全验证
    },
  };
  // add your middleware conhfig here
  config.middleware = [];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };
  config.pathConfig = {
    domainName : 'http://localhost:1888',
    uploadPath : 'app/public/upload'
  }
  config.cluster = {
    listen: {
      path: '',
      port: 1888,
      hostname: 'localhost',
    }
  };

  config.code = {
    SUCCESS: 200,         //success
    REDIRECT: 304,        //redirect
    UN_LOGIN: 10001,      //没有登录
    BIND_PHONE: 10002,     //没有绑定手机,
    MESSAGE: 10003,          //消息提醒
    LOGIN_EXPIRE: 10004     //登录过期
  }

  config.sendJson = (obj) => {
    return {
      code: obj.code || config.code.SUCCESS,
      message: obj.message || '',
      data: obj.data || ''
    }
  }


  config.mysql = {
    // 单数据库信息配置
    client: {
      // host
      host: 'localhost',
      // 端口号
      port: '3306',
      // 用户名
      user: 'root',
      // 密码
      password: 'root',
      // 数据库名
      database: 'ydblog',
    },
    // 是否加载到 app 上，默认开启
    app: true,
    // 是否加载到 agent 上，默认关闭
    agent: false,
  };

  //跨域 - 允许访问接口
  config.cors = {
    enable: false,
    origin: '*', // 表示允许的源
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH' // 表示允许的http请求方式
  };

  //token 配置
  config.jwt = {  //jwt配置项
    secret: "123456"
  }

  return {
    ...config,
    ...userConfig,
  };
};